package com.xiaocheng.core.memento;

import java.util.ArrayList;
import java.util.List;

public class Originator {
	private List<String> status;
	private int index;
	public Originator(){
		status = new ArrayList<>();
		index = -1;
	}
	public Originator(List<String> status){
		this.status = status;
		index = status.size();
	}
	public MementoInterface createMemento(){
		return new Memento(status, index);
	}
	public List<String> getStatus() {
		return status;
	}
	/**
     * 将发起人恢复到备忘录对象记录的状态上
     */
    public void restoreMemento(MementoInterface memento){
    	
        status = memento.getStatus();
        index = memento.getIndex();
    }
	public void setStatus(String state){
        status.add(state);
        index++;
    }
	
	public int getIndex() {
		return index;
	}
	public void printStatus(){
		System.err.println(status.get(index));
	}
	
}
